// Package ioc
// Created by GoLand
// @User: lenora
// @Date: 2023/12/17
// @Time: 15:44

package ioc

import (
	"camp/microbook/config"
	rlock "github.com/gotomicro/redis-lock"
	"github.com/redis/go-redis/v9"
	"github.com/spf13/viper"
)

func InitRedis() redis.Cmdable {
	var conf config.RedisConfig
	err := viper.UnmarshalKey("redis", &conf)
	if err != nil {
		panic(err)
	}
	redisClient := redis.NewClient(&redis.Options{
		//Addr: "localhost:6377",
		Addr: conf.Addr,
	})
	return redisClient
}

func InitRLockClient(cmdable redis.Cmdable) *rlock.Client {
	return rlock.NewClient(cmdable)
}
